package com.rran.study.concurrent.safeend;

/**
 * @author yy
 * @Type EndRunnable.java
 * @Desc 实现接口Runnable的线程如何中断
 * @date 2020/7/29 11:31
 */
public class EndRunnable {

    private static class MyRunnable implements Runnable {

        @Override
        public void run() {
            while (!Thread.currentThread().isInterrupted()){
                System.out.println(Thread.currentThread().getName()+"线程正在执行");
            }
            System.out.println(Thread.currentThread().getName()+"线程被中断");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new MyRunnable(),"myThread");
        thread.start();
        Thread.sleep(200);
        thread.interrupt();
    }

}
